<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>${constants.getSystemName()}</title>
    <link rel="stylesheet" href="${ctxPath}/assets/common/libs/layui/css/layui.css?v=${constants.getReleaseVersion()}"/>
    <link rel="stylesheet" href="${ctxPath}/assets/common/module/admin.css?v=${constants.getReleaseVersion()}"/>
    <link rel="stylesheet" href="${ctxPath}/assets/expand/css/style.css?v=${constants.getReleaseVersion()}" media="all"/>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15" >
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="currentSession" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="maxSession" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="maxSeconds" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space15" >
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="createTotal" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="rejectTotal" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div id="expiredTotal" style="width: 100%;min-height:300px"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- js部分 -->
    @/* 加入contextPath属性和session超时的配置 */
    <script type="text/javascript">
        var Feng = {
            ctxPath: "${ctxPath}",
            version: '${constants.getReleaseVersion()}'
        };
    </script>
    <script type="text/javascript" src="${ctxPath}/assets/common/libs/layui/layui.js?v=${constants.getReleaseVersion()}"></script>
    <script type="text/javascript" src="${ctxPath}/assets/common/js/common.js?v=${constants.getReleaseVersion()}"></script>
    <script src="${ctxPath}/assets/common/libs/echarts/echarts.min.js?v=${constants.getReleaseVersion()}"></script>
    <script src="${ctxPath}/assets/common/libs/echarts/echartsTheme.js?v=${constants.getReleaseVersion()}"></script>
    <script src="${ctxPath}/assets/common/js/echartInit.js?v=${constants.getReleaseVersion()}"></script>
    <script>
        layui.use(['layer','HttpRequest'], function () {
            const $ = layui.jquery;
            let HttpRequest = layui.HttpRequest;
            const tomcatBaseUrl = "/view/monitor/getTomcatInfo";
            let tomcatRequest = new HttpRequest(tomcatBaseUrl, 'get',function (data) {
                console.log(data)
                let currentParams = {
                    id: 'currentSession',
                    title : 'Current Sessions',
                    metric: data.tomcat_sessions_active_current_sessions
                }
                initGraph1(currentParams);
                let maxParams = {
                    id: 'maxSession',
                    title : 'Max Sessions',
                    metric: data.tomcat_sessions_active_max_sessions
                }
                initGraph1(maxParams);
                let msParams = {
                    id: 'maxSeconds',
                    title : 'Max Seconds',
                    metric: data.tomcat_sessions_alive_max_seconds
                }
                initGraph1(msParams);
                let ctParams = {
                    id: 'createTotal',
                    title : 'Total Create',
                    metric: data.tomcat_sessions_created_sessions_total
                }
                initGraph1(ctParams);
                let rtParams = {
                    id: 'rejectTotal',
                    title : 'Total Reject',
                    metric: data.tomcat_sessions_rejected_sessions_total
                }
                initGraph1(rtParams);
                let exParams = {
                    id: 'expiredTotal',
                    title : 'Total Expired',
                    metric: data.tomcat_sessions_expired_sessions_total
                }
                initGraph1(exParams);
            })
            tomcatRequest.setAsync(true);
            tomcatRequest.start();

            function initGraph1(params) {
                const paramsId = echarts.init(document.getElementById(params.id), myEchartsTheme);
                let metricData = params.metric;
                const option = {
                    title: {
                        text: params.id,
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'axis',
                        formatter: function (datas){
                            let res;
                            datas.map(function (e,i) {
                                if (res == undefined){
                                    let datetime = new Date(e.value[0]*1000);
                                    res = datetime.getUTCFullYear().toString()+'-'+datetime.getUTCMonth().toString()+'-'+datetime.getUTCDate().toString()+' '+datetime.getHours().toString()+':'+ datetime.getMinutes().toString() + ':' + datetime.getSeconds().toString() + '<br/>'
                                }
                                if (params.unit === 'MB' && e.value[1]>0){
                                    res += e.marker +" " + e.seriesName + ' : ' + (e.value[1]/1000/1000).toFixed(2) + params.unit + '<br/>'
                                }              else {
                                    res += e.marker +" " + e.seriesName + ' : ' + e.value[1] + '<br/>'
                                }
                            })
                            return res;
                        }
                    },
                    xAxis: {
                        type: 'time',
                        axisLabel: {
                            formatter: function(value,index){
                                let datetime = new Date(value*1000)
                                return datetime.getHours().toString()+':'+ datetime.getMinutes().toString()
                            }
                        }
                    },
                    yAxis: {
                        name: params.unit,
                        type: 'value',
                        scale: true,
                        axisLabel: {
                            formatter: function(value,index){
                                if (params.unit == 'MB' && value>0){
                                    return value/1000/1000
                                } else {
                                    return value
                                }
                            }
                        }
                    },
                    series: [{type : 'line',
                        smooth: true,
                        animationDuration: 2000,
                        animationEasing: 'quadraticOut',
                        name : params.id,
                        data: metricData,
                        areaStyle: {            // 折现下是否填充
                            color: this.color,
                            opacity: 0.6
                        },
                        showSymbol: false}],
                };
                paramsId.setOption(option);
            }
        });
    </script>
</body>
</html>